import { createRouter, createWebHashHistory } from 'vue-router';

//动态路由
export const permissionRouter = [
    {
        name:'adminManage',
        path:'/a',
        component:() => import('@/view/layout/index.vue'),
        redirect:{path:"/adminuser"},
        children:[
            {
                name:"AdminUser",
                path:"/adminuser",
                component:()=>import("@/view/adminUser/index.vue"),
                meta:{title:"用户管理",hidden:false,icon:"User"}
            }
        ],
        meta:{title:"",hidden:false,icon:"House"}
    }
]

//常量路由配置
export const constantRouter = [
    {
        name:'login',
        path:'/login',
        component:() => import('@/view/login/index.vue'),
        meta:{title:"登录",hidden:true,icon:""}
    },
    {
        name:'layout',
        path:'/',
        component:() => import('@/view/layout/index.vue'),
        redirect:{path:"/home"},
        children:[
            {
                name:"Home",
                path:"/home",
                component:()=>import('@/view/home/index.vue'),
                meta:{title:"首页",hidden:false,icon:"House"}
            }
        ],
        meta:{title:"layout",hidden:false,icon:"House"}
    },
    {
        name:"Screen",
        path:"/screen",
        component:()=>import("@/view/screen/index.vue"),
        meta:{title:"数据统计",hidden:false,icon:"Monitor"}
    },
    {
        name:'404',
        path:'/404',
        component:() => import('@/view/error/index.vue'),
        meta:{title:"404",hidden:true}
    }
]

//任意路由配置
export const anyRouter = [
    {
        name:'any',
        path:'/:pathMatch(.*)*',
        redirect:'/404',
        meta:{hidden:true}
    }
]

//管理相关的路由
export const manageRouter = [
    {
        name:"Product",
        path:"/product",
        component:()=>import("@/view/layout/index.vue"),
        redirect:{path:''},
        children:[
            {
                name:"Category",
                path:"/product/category",
                component:()=>import('@/view/product/category/index.vue'),
                meta:{title:"商品分类管理",hidden:false,icon:"Film"}
            },
            {
                name:"Attr",
                path:"/product/attr",
                component:()=>import('@/view/product/attr/index.vue'),
                meta:{title:"商品规格管理",hidden:false,icon:"Collection"}
            },
            {
                name:"Commodity",
                path:"/product/commodity",
                component:()=>import('@/view/product/commodity/index.vue'),
                meta:{title:"商品详情管理",hidden:false,icon:"Document"}
            }
        ],
        meta:{title:"商品管理",hidden:false,icon:"Goods"}
    },
    {
        name:'orderManage',
        path:'/o',
        component:() => import('@/view/layout/index.vue'),
        redirect:{path:"/order"},
        children:[
            {
                name:"Order",
                path:"/order",
                component:()=>import("@/view/order/index.vue"),
                meta:{title:"订单管理",hidden:false,icon:"Memo"}
            }
        ],
        meta:{title:"",hidden:false,icon:"House"}
    },
    {
        name:'userManage',
        path:'/u',
        component:() => import('@/view/layout/index.vue'),
        redirect:{path:"/user"},
        children:[
            {
                name:"User",
                path:"/user",
                component:()=>import("@/view/user/index.vue"),
                meta:{title:"会员管理",hidden:false,icon:"UserFilled"}
            },
        ],
        meta:{title:"",hidden:false,icon:"House"}
    }
]

const routerList = [...constantRouter,...manageRouter,...anyRouter];

let router = createRouter({
    history:createWebHashHistory(),
    routes:routerList,  //当前仅注册了常量路由，其它路径在获取用户权限信息后进行动态添加
    //滚动行为
    scrollBehavior(){
        return{
            left:0,
            top:0
        }
    }
})



export default router;